package org.net.cms.controller.app.leave;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.net.cms.config.Result;
import org.net.cms.controller.app.leave.vo.AppStudentLeaveReqVO;
import org.net.cms.controller.app.leave.vo.AppStudentLeaveRespVO;
import org.net.cms.service.leave.StudentLeaveService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app/leave")
@Tag(name = "APP - 学生请假")
public class AppStudentLeaveController {

    @Resource
    private StudentLeaveService studentLeaveService;

    @PostMapping("/add")
    @Operation(summary = "新增学生请假请求")
    public Result add(@RequestBody AppStudentLeaveReqVO studentLeaveReqVO) {
        studentLeaveService.insert(studentLeaveReqVO);
        return Result.success();
    }

    @PostMapping("/delete")
    @Operation(summary = "删除学生请假请求")
    @Parameter(name = "id", description = "请假id", required = true)
    public Result delete(int id) {
        studentLeaveService.delete(id);
        return Result.success();
    }

    @PostMapping("/update")
    @Operation(summary = "修改学生请假请求")
    public Result delete(@RequestBody AppStudentLeaveRespVO studentLeaveRespVO) {
        studentLeaveService.updateLeave(studentLeaveRespVO);
        return Result.success();
    }

    @GetMapping("/get")
    @Operation(summary = "获取请假详情")
    @Parameter(name = "id", description = "请假id", required = true)
    public Result get(int id) {
        return Result.success(studentLeaveService.findById(id));
    }

    @GetMapping("/list")
    @Operation(summary = "获取当前用户请假列表")
    public Result list() {
        return Result.success(studentLeaveService.findAll());
    }
}
